package common;

import java.io.BufferedReader;
import java.io.BufferedWriter;

import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.util.Log;
import config.*;

public class SystemFunction {	
	public boolean GetWebServer( AssetManager am) { 	
		try{		                     
		InputStream inputStream = am.open("server.txt", AssetManager.ACCESS_BUFFER);
		BufferedReader f = new BufferedReader(new InputStreamReader(inputStream));
		String line = f.readLine();
		if(line != null) {	
			config.SERVER_URL = line;
			return true;	   
		}			
		}catch(Exception ex){
			return false;
		}
		return false;
		
	}
	
	public boolean SetWebServer(String webserver , AssetManager am) throws IOException{ 				
		try{		                     
			
			
		    String[] files = null;
		    try {
		        files = am.list("");
		    } catch (IOException e) {
		        Log.e("tag", "Failed to get asset file list.", e);
		    }
		    
			AssetFileDescriptor descriptor = am.openNonAssetFd(files[1]);
			BufferedWriter w = new BufferedWriter(new FileWriter(descriptor.getFileDescriptor()));
			w.write(webserver);
			}catch(Exception ex){
				return false;
			}
			return false;
	}
	
}
